
#ifndef __COMMON_HPP__
#define __COMMON_HPP__

// =========================================================
// Common Includes And Definition For The Application
// =========================================================

// C / C++
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <assert.h>

// Local
#include "Socket.hpp"
#include "Thread.hpp"

#ifdef _MSC_VER
// Disable The CRT Lib Deprecation Warning on VS.
#pragma warning (disable: 4996)
#endif

#define LOG_MSG(x) { std::cout << x << '\n'; }
#define LOG_ERROR(x) { std::cout << "Error: " << x << '\n'; }
#define LOG_WARNING(x) { std::cout << "Warning: " << x << '\n'; }
#define LOG_FATAL_ERROR(x) { std::cout << "Fatal Error! " << x << " Terminating Application..." << '\n'; exit(EXIT_FAILURE); }

// Unix - Win Portability Macros
#ifdef _WIN32
#define CLEAR_CONSOLE() system("cls")
#define SLEEP_MS(millisec) Sleep(millisec)
#else
#define SLEEP_MS(millisec) usleep((millisec) * 1000)
#define CLEAR_CONSOLE() system("clear")
#endif

// When This Directive Is Set The Compiler Will Enable Sleep() Calls
// In The Main Threads, Wich May Be Good On Less Powerfull Machines, Since This Will Decrease The Processor Load.
// Note That This Is A VERY Rudimentary Way Of Controlling CPU Usage, But Will Do For Now.
//#define DROP_FRAME_RATE
#define COOL_DOWN_TIME 5

// == Game Related Data ======

// The Tic Tac Toe Board.
#define BOARD_ROWS 3
#define BOARD_COLS 3

// Player State Flags.
#define PLAYER_WAITING	(1 << 0)
#define PLAYER_IN_GAME	(1 << 1)
#define PLAYER_WON		(1 << 2)
#define PLAYER_LOST		(1 << 3)
#define PLAYER_DRAW		(1 << 4)

struct ServerMessage {

	int playerFlags; // Player Status (Win, Loose, etc...)
	char gameBoard[BOARD_ROWS][BOARD_COLS]; // Updated Board.
};

struct ClientMessage {

	// What The Player Changed.
	int updatedRow;
	int updatedCol;
};

#define ASCII_MSG_MAX_LEN 64

#endif // __COMMON_HPP__
